SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		EM
-- Create date: 2012-06-13
-- Description:	session alert
-- =============================================
alter TRIGGER dbo.InsNewSession
   ON  dbo.user_sessions 
   AFTER INSERT
AS 
BEGIN

	SET NOCOUNT ON;
declare @phone varchar(20), @Code varchar(160), @h int, @comment varchar(255), @phone_id int, @uid int
select @phone_id =phone_id, @h=datepart(hh,dt) from inserted i 
--print @phone_id
--print @h
select @phone=phone , @uid=uid from dbdata.dbo.phones where id=@phone_id
--print @phone
set @Code='NewSession '+@phone+' '+convert(varchar,getdate(),102)+' '+cast(@h as varchar)+':**'
set @comment='hour: '+cast(@h as varchar)
EXEC	sms_p.[dbo].[sp_SetSMSEmailNotification]
		@SMS_ID = @uid,
		@Code =@Code,
		@Comment = @comment


END
GO
